﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Midi;

namespace MIDIRemapper.DeviceInterfaces
{
    partial class DeviceInterface
    {
        private Dictionary<MidiType, int> transposers
            = new Dictionary<MidiType, int>();

        /// <summary>
        /// Add a transpose route
        /// </summary>
        /// <param name="t_in">MIDIType of input midi message to apply to</param>
        /// <param name="interval">Positive or negative number of value ticks to transpose</param>
        public void AddTranspose(MidiType t_in, int interval)
        {
            transposers.Add(t_in, interval);
        }

        public void RemoveTransposer(int i)
        {
            transposers.Remove(globalMatches.Keys.ElementAt(i));
        }

        public void LoadTransposer(Dictionary<MidiType, int> tr)
        {
            transposers = tr;
        }
        
        /// <summary>
        /// Looks for a match for the given MIDIType, returns it via out parameter
        /// </summary>
        /// <param name="t_in">Input type</param>
        /// <param name="t_out">Sets the output type associated with the input</param>
        /// <returns>Match found</returns>
        bool GetTranspose(MidiType t_in, out int interval)
        {
            return transposers.TryGetValue(t_in, out interval);
        }

        public Dictionary<MidiType, int> GetTransposers()
        {
            return transposers;
        }

        private void AddTranspose(KeyValuePair<MidiType, int> route)
        {
            transposers.Add(route.Key, route.Value);
        }
    }
}
